package frontend.parser.syntaxtree;

import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * CompUnit结点
 *
 * @author 杨凯伟
 * @date 2024/10/14
 */
public class CompUnitNode extends SyntaxNode {
    public final List<DeclNode> declares = new ArrayList<>();
    public final List<FuncDefNode> functions = new ArrayList<>();
    public MainFuncDefNode mainFunc;

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        declares.forEach(declare -> declare.walk(terConsumer, nonTerConsumer));
        functions.forEach(func -> func.walk(terConsumer, nonTerConsumer));
        mainFunc.walk(terConsumer, nonTerConsumer);
        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }

    @Override
    public String getType() {
        return "CompUnit";
    }
}
